﻿//地图着色
var colored = false;//是否着色
require(["dojo/parser", "dojo/on", "esri/layers/FeatureLayer", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
          "esri/renderers/UniqueValueRenderer", "esri/InfoTemplate", "esri/Color", "dojo/domReady!"],
    function (parser, on, FeatureLayer, SimpleLineSymbol, SimpleFillSymbol,UniqueValueRenderer, InfoTemplate, Color) {
        on(document.getElementById("color"), "click", function () {
            if (!colored) {
                addFeatureLayer();
            }
            colored = true;
        });
        function addFeatureLayer() {
            var defaultSymbol = new SimpleFillSymbol().setStyle(SimpleFillSymbol.STYLE_NULL);
            defaultSymbol.outline.setStyle(SimpleLineSymbol.STYLE_NULL);
            // 创建渲染器
            var renderer = new UniqueValueRenderer(defaultSymbol, "LAYER");
            // 为每个可能的值增加一个符号
            renderer.addValue("jd", new SimpleFillSymbol().setColor(new Color([0, 153, 0, 0.8])));
            renderer.addValue("yq", new SimpleFillSymbol().setColor(new Color([0, 0, 0, 0.8])));
            renderer.addValue("dk", new SimpleFillSymbol().setColor(new Color([204, 102, 0, 0.8])));
            featureLayer = new FeatureLayer(getMapUrl()+"/2", {
                infoTemplate: new InfoTemplate("${YQMC}", "能级分类：${能级分类}<br>面积：${AREA}"),
                mode: FeatureLayer.MODE_ONDEMAND,
                outFields: ["*"]
            });
            featureLayer.setRenderer(renderer);
            map.addLayer(featureLayer);
            
        }
    });